package com.mzkj.wanjulaile.mobile.api.modules.toy.controller;

import com.mzkj.common.data.StatusCode;
import com.mzkj.wanjulaile.mobile.api.common.controller.BaseController;
import com.mzkj.wanjulaile.mobile.api.common.entity.ResultEntity;
import com.mzkj.wanjulaile.mobile.api.modules.toy.entity.Image;
import com.mzkj.wanjulaile.mobile.api.modules.toy.entity.Toy;
import com.mzkj.wanjulaile.mobile.api.modules.toy.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "image")
public class ImageController extends BaseController {
    @Autowired
    private ImageService imageService;

    /**
     * 获取说明书列表
     * @param id  (id:玩具id)
     * @return
     */
    @RequestMapping(value = "getInsList")
    @ResponseBody
    public ResultEntity<List> getIstruction(String id ) {
        ResultEntity<List> result = new ResultEntity<>();
        try {
            Image instruction = new Image();
            instruction.setToy(new Toy(id));
            List<Image> instructionList = imageService.getInstructions(instruction);
            result.setData(instructionList);
            result.setStatusCode(StatusCode.SC0.getValue());
            result.setMsg(StatusCode.SC0.getDesc());
        } catch (Exception e) {
            e.printStackTrace();
            result.setStatusCode(StatusCode.SC4002.getValue());
            result.setMsg(StatusCode.SC4002.getDesc());
        }
        return result;
    }
}